<?php
if(!isset($MAIN)){
	include_once("includes/class.ibnfm.php");
	$MAIN = new MAIN();
}
require_once("includes/dompdf_config.inc.php");

$reg=$MAIN->registrations->getRegistration($_REQUEST['id']);

switch($reg['type']){	
	case "Studiecirkel":
	case "Annan":
	case "Annan Verksamhet":
		$summer = $reg['semester']=='summer'?'[x]':'[ ]';
		$autumn = $reg['semester']=='autumn'?'[x]':'[ ]';
		$as = $MAIN->associations->getAssociation(@$reg['association_id']);
$html = '
<html>
<head>
<style>
body{
	padding:30px;
	font-family:helvetica;
	font-size:14px;
}
h1{
	font-size: 18px;
	padding:3px;
}
h2{
	font-size: 18px;
	padding:3px;
}
</style>
</head>
<body>	
	<table cellpadding="0" cellspacing="0" style="width:100%;">
	<tr>
		<td style="vertical-align:bottom;">
		<span style="font-size:10px;">
		|IBN RUSHD STUDIFÖRBUND|<br/>
		|DISTRIKT SÖDRA|<br/>
		|ER STUDIEKONSULENT:ROMDHANE BOUSSAIDI|<br/>
		|VXL ---------------- MBL.07868-55 86 12 - KONTOR 040-8 13 10|<br/>		
		</span>
		<h1>Föranmälan</h1></td>
		<td style="text-align:right;">
			<img src="images/ibn_rushd_logo.jpg" alt=""/>
		</td>
	</tr>
	</table>	
	<div style="text-align:center;">
		'.$summer.' Vårterminen (01 jan - 30 juni)
		&nbsp;&nbsp;&nbsp;
		'.$autumn.' Höstterminen (01 jul - 30 dec)&nbsp;&nbsp;&nbsp;
	</div>	
	<div style="border:2px solid #000;">
		<label for="txt_association_name">Föreningsnamn</label>
		<div style="position:relative;">		
		<div>'.$as["name"].'</div>
		</div>
		<hr style="height:1px; background-color:#000; border:0px;"/>
		<table cellpadding="0" cellspacing="0" style="width:100%;">
			<tr>
				<td style="width:65%;">
					<label for="txt_association_address">Förenings adress</label>
					<div>'.$as["address"].'</div>
				</td>
				<td style="width:15%;">
					<label for="txt_association_zip">Postnummer</label>
					<div>'.$as["zip"].'</div>
				</td>
				<td style="width:20%;">
					<label for="txt_association_city">Ort</label>
					<div>'.$as["city"].'</div>
				</td>
			</tr>
		</table>
		<hr style="height:1px; background-color:#000; border:0px;"/>
		<label for="ddl_association_member_of">Medlem i:</label>
		<div id="association_member_of_list" style="display:inline-block;">';
$mmemberof = explode(",",$as["member_of"]);
$membersof=$MAIN->returnArray("select * from `".tblPrefix."memberof`");	
foreach($membersof as $m){
	if(in_array($m["id"],$mmemberof)){$checked='[x]'; }else{$checked='[ ]';}
	$html.='
	 <label for="">'.$checked.' '.$m["name"].'</label>	
	';
}
$circle = $MAIN->circles->getCircle($reg["circle_id"]);
$html.='</div>
		<br/>
	</div>
	<br/>
	<h2>Studiecirkeln/Annan Folkbildningsverksamheten</h2>
	<div style="border:2px solid #000;">
		<label for="txt_circle_name">Studiecirkelns namn</label>		
		<div style="position:relative;">
		<div>'.$circle["name"].'</div>		
		</div>
		<hr style="height:1px; background-color:#000; border:0px;"/>
		<label for="txt_circle_topic">Ämne</label>
		<div>'.$circle["topic"].'</div>
		<hr style="height:1px; background-color:#000; border:0px;"/>
		<label for="txt_circle_topic">Material</label>
		<div>'.$circle["material"].'</div>
		<hr style="height:1px; background-color:#000; border:0px;"/>
		<table cellpadding="0" cellspacing="0" style="width:100%;">
			<tr>
				<td style="width:19%;">
					<label for="txt_circle_start_date">Startdatum</label>
					<div>'.$circle["start_date"].'</div>
				</td>
				<td style="width:19%;">
					<label for="txt_circle_day_of_the_week">Veckodag</label>
					<div>'.$circle["day_of_the_week"].'</div>
				</td>
				<td style="width:19%;">
					<label for="txt_circle_start">Starttid</label>
					<div>'.$circle["start"].'</div>
				</td>
				<td style="width:19%;">
					<label for="txt_circle_end">sluttid</label>
					<div>'.$circle["end"].'</div>
				</td>
				<td style="width:24%;text-align:center;">
					<label for="txt_circle_number_of_meetings">Antal träffar(per termin)</label>
					<div>'.$circle["number_of_meetings"].'</div>
				</td>
			</tr>
		</table>
		<hr style="height:1px; background-color:#000; border:0px;"/>
		<table cellpadding="0" cellspacing="0" style="width:100%;">
			<tr>
				<td style="width:65%;">
					<label for="txt_circle_place">Studiecirkelns adress</label>
					<div>'.$circle["place"].'</div>
				</td>
				<td style="width:15%;">
					<label for="txt_circle_zip">Postnummer</label>
					<div>'.$circle["zip"].'</div>
				</td>
				<td style="width:20%;">
					<label for="txt_circle_city">Ort</label>
					<div>'.$circle["city"].'</div>
				</td>
			</tr>
		</table>
	</div><br/>';
$leader = $MAIN->persons->getPerson($reg["leader_id"]);
$html.='		
	<h2>Cirkelledaren</h2>
	<div style="border:2px solid #000;">		
		<table cellpadding="0" cellspacing="0" style="width:100%;">
			<tr>
				<td style="width:35%;">
					<label for="txt_leader_firstname">Förnamn</label>
					<div>'.$leader["firstname"].'</div>
				</td>
				<td style="width:35%;">
					<label for="txt_leader_lastname">Efternamn</label>
					<div>'.$leader["lastname"].'</div>
				</td>
				<td style="width:30%;">
					<label for="txt_leader_pers">Personnummer</label>
					<div>'.$leader["pers"].'</div>
				</td>
			</tr>
		</table>
		<hr style="height:1px; background-color:#000; border:0px;"/>
		<table cellpadding="0" cellspacing="0" style="width:100%;">
			<tr>
				<td style="width:65%;">
					<label for="txt_leader_address">Adress</label>
					<div>'.$leader["address"].'</div>
				</td>
				<td style="width:15%;">
					<label for="txt_leader_zip">Postnummer</label>
					<div>'.$leader["zip"].'</div>
				</td>
				<td style="width:20%;">
					<label for="txt_leader_city">Ort</label>
					<div>'.$leader["city"].'</div>
				</td>
			</tr>
		</table>
		<hr style="height:1px; background-color:#000; border:0px;"/>
		<table cellpadding="0" cellspacing="0" style="width:100%;">
			<tr>
				<td style="width:80%;">
					<label for="txt_leader_email">E-mejl adress</label>
					<div>'.$leader["emailp"].'</div>
				</td>			
				<td style="width:20%;">
					<label for="txt_leader_tel">Telefonnummer</label>
					<div>'.$leader["tel"].'</div>
				</td>
			</tr>
		</table>
	</div><br/>';

$html.='
	<h2>Deltagarföteckning</h2>
	<div id="participants_list">';

	$members=explode(",",$reg["members"]);
	
	$min = count($members);
	if($min<3){$min=3;}
	for($i=0;$i<$min;$i++){
		$member = $MAIN->persons->getPerson($members[$i]);
$html.='
	<div class="cnt_participant" style="border:2px solid #000; margin-bottom:5px;">
		<input type="hidden" name="txt_participant_id_<?php echo($i);?>" id="txt_participant_id_<?php echo($i);?>" value=""/>
		<table cellpadding="0" cellspacing="0" style="width:100%;">
			<tr>
				<td style="width:40%;">
					<label for="txt_participant_firstname_<?php echo($i);?>">Förnamn</label>
					<div>'.$member["firstname"].'</div>
				</td>
				<td style="width:40%;">
					<label for="txt_participant_lastname_<?php echo($i);?>">Efternamn</label>
					<div>'.$member["lastname"].'</div>
				</td>
				<td style="width:20%;">
					<label for="txt_participant_pers_<?php echo($i);?>">Personnummer</label>
					<div>'.$member["pers"].'</div>
				</td>
			</tr>
		</table>
		<hr style="height:1px; background-color:#000; border:0px;"/>
		<table cellpadding="0" cellspacing="0" style="width:100%;">
			<tr>
				<td style="width:40%;">
					<label for="">Address</label>
					<div>'.$member["address"].'</div>
				</td>
				<td style="width:20%;">
					<label for="">Postnummer</label>
					<div>'.$member["zip"].'</div>
				</td>
				<td style="width:20%;">
					<label for="">Ort</label>
					<div>'.$member["city"].'</div>
				</td>			
				<td style="width:20%;">
					<label for="">Telefonnummer</label>
					<div>'.$member["tel"].'</div>
				</td>
			</tr>
		</table>
	</div>';
	}
$html.='
	</div>
	</body>
	</html>
';
	break;
	case 'Kulturprogram':
		$summer = $reg['semester']=='summer'?'[x]':'[ ]';
		$autumn = $reg['semester']=='autumn'?'[x]':'[ ]';
		$as = $MAIN->associations->getAssociation(@$reg['association_id']);
$html = '
<html>
<head>
<style>
body{
	padding:30px;
	font-family:helvetica;
	font-size:14px;
}
h1{
	font-size: 18px;
	padding:3px;
}
h2{
	font-size: 18px;
	padding:3px;
}
h3{
	font-size: 16px;
	padding:0px;
	margin:0px;
}
</style>
</head>
<body>
	<table cellpadding="0" cellspacing="0" style="width:100%;">
	<tr>
		<td style="vertical-align:bottom;">
			<br/><br/><br/><h1>Anmälan av Kulturprogram</h1>
		</td>
		<td style="text-align:right;">
			<img src="images/ibn_rushd_logo.jpg" alt=""/>
		</td>
	</tr>
	</table>
	<div style="text-align:center;">
		'.$summer.' Vårterminen (01 jan - 30 juni)
		&nbsp;&nbsp;&nbsp;
		'.$autumn.' Höstterminen (01 jul - 30 dec)&nbsp;&nbsp;&nbsp;
	</div>	
	<div style="border:2px solid #000;">
		<label for="txt_association_name">Föreningsnamn</label>
		<div style="position:relative;">		
		<div>'.$as["name"].'</div>
		</div>
		<hr style="height:1px; background-color:#000; border:0px;"/>
		<table cellpadding="0" cellspacing="0" style="width:100%;">
			<tr>
				<td style="width:65%;">
					<label for="txt_association_address">Förenings adress</label>
					<div>'.$as["address"].'</div>
				</td>
				<td style="width:15%;">
					<label for="txt_association_zip">Postnummer</label>
					<div>'.$as["zip"].'</div>
				</td>
				<td style="width:20%;">
					<label for="txt_association_city">Ort</label>
					<div>'.$as["city"].'</div>
				</td>
			</tr>
		</table>
		<hr style="height:1px; background-color:#000; border:0px;"/>
		<label for="ddl_association_member_of">Medlem i:</label>
		<div id="association_member_of_list" style="display:inline-block;">';
$mmemberof = explode(",",$as["member_of"]);
$membersof=$MAIN->returnArray("select * from `".tblPrefix."memberof`");	
foreach($membersof as $m){
	if(in_array($m["id"],$mmemberof)){$checked='[x]'; }else{$checked='[ ]';}
	$html.='
	 <label for="">'.$checked.' '.$m["name"].'</label>	
	';
}
$circle = $MAIN->circles->getCircle($reg["circle_id"]);
$html.='</div>
		<br/>
	</div>
	<br/>';

$html.='<h2>Kontaktperson - ansvarar för att nedanstående uppgifter är korrekta</h2>';
$leader = $MAIN->persons->getPerson($reg['leader_id']);
	
$html.='<div style="border:2px solid #000;">		
		<table cellpadding="0" cellspacing="0" style="width:100%;">
			<tr>
				<td style="width:40%;">
					<label for="txt_leader_firstname">Förnamn</label>
					<div>'.$leader["firstname"].'</div>
				</td>
				<td style="width:40%;">
					<label for="txt_leader_lastname">Efternamn</label>
					<div>'.$leader["lastname"].'</div>
				</td>
				<td style="width:20%;">
					<label for="txt_leader_pers">Personnummer</label>
					<div>'.$leader["pers"].'</div>
				</td>
			</tr>
		</table>
		<hr style="height:1px; background-color:#000; border:0px;"/>
		<table cellpadding="0" cellspacing="0" style="width:100%;">
			<tr>
				<td style="width:65%;">
					<label for="txt_leader_address">Adress</label>
					<div>'.$leader["address"].'</div>
				</td>
				<td style="width:15%;">
					<label for="txt_leader_zip">Postnummer</label>
					<div>'.$leader["zip"].'</div>
				</td>
				<td style="width:20%;">
					<label for="txt_leader_city">Ort</label>
					<div>'.$leader["city"].'</div>
				</td>
			</tr>
		</table>
		<hr style="height:1px; background-color:#000; border:0px;"/>
		<table cellpadding="0" cellspacing="0" style="width:100%;">
			<tr>
				<td style="width:80%;">
					<label for="txt_leader_email">E-mejl adress</label>
					<div>'.$leader["emailp"].'</div>
				</td>			
				<td style="width:20%;">
					<label for="txt_leader_tel">Telefonnummer</label>
					<div>'.$leader["tel"].'</div>
				</td>
			</tr>
		</table>
	</div><br/>';
$programs=explode(",",$reg['programs']);
$min = count($programs);
if($min<3){$min=3;}
for($i=0;$i<$min;$i++){
	$circle=$MAIN->circles->getCircle(@$programs[$i]);	
$html.='<h3>KP'.($i+1).'</h3>
	<div class="cnt_program" id="cnt_program_<?php echo($i);?>" style="border:2px solid #000; margin-bottom:5px;">		
		<table cellpadding="0" cellspacing="0" style="width:100%;">
			<tr>
				<td>
					<label for="">Program</label>
					<div>'.$circle["name"].'</div>
				</td>
				<td>
					<label for="">Ämne</label>
					<div>'.$circle["topic"].'</div>					
				</td>
			</tr>
		</table>
		<hr style="height:1px; background-color:#000; border:0px;"/>
		<table cellpadding="0" cellspacing="0" style="width:100%;">
			<tr>
				<td>
					<label for="">Datum</label>
					<div>'.$circle["start_date"].'</div>
				</td>
				<td>
					<label for="">Starttid</label>
					<div>'.$circle["start"].'</div>
				</td>
				<td>
					<label for="">Sluttid</label>
					<div>'.$circle["end"].'</div>
				</td>
				<td>
					<label for="">Antal Medverkande</label>
					<div>'.$circle["number_of_participants"].'</div>
				</td>
			</tr>
		</table>
		<hr style="height:1px; background-color:#000; border:0px;"/>
		<table cellpadding="0" cellspacing="0" style="width:100%;">
			<tr>
				<td>
					<label for="">Lokal(ange namn och fullständig adress)</label>
					<div>'.$circle["place"].'</div>
				</td>
			</tr>
		</table>
	</div>';
}
	
$html.='
	</body>
	</html>
';
	break;
}

//if (get_magic_quotes_gpc())
//$html = stripslashes($html);

$html = iconv('UTF-8','ISO-8859-1',$html);
$dompdf = new DOMPDF();
$dompdf->load_html($html);
$dompdf->set_paper("a4", "portrait");
$dompdf->render();
$dompdf->stream("regsitration.pdf", array("Attachment" => true));
exit(0);

?>